//
//  HomePageHeaderView.m
//  Mtime2.0
//
//  Created by 凉气的Mac on 16/9/3.
//  Copyright © 2016年 凉气的Mac. All rights reserved.
//

#import "HomePageHeaderView.h"

@interface HomePageHeaderView ()<UIScrollViewDelegate>

@property(nonatomic,weak) UIScrollView *scrollView;

@end

@implementation HomePageHeaderView


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:CGRectMake(0, 0, 0, 200)]) {
        
        //设置界面
        [self setupUI];
        
    }
    return self;
}

#pragma mark --
#pragma mark --设置界面
-(void)setupUI{
    
    [self addScrollView];
    [self addSearchBtn];
    [self addPageControl];
    [self addCoverView];

}

#pragma mark --
#pragma mark --添加scrollView
-(void)addScrollView{

    UIScrollView *scrollView = [[UIScrollView alloc]init];
    
    self.scrollView = scrollView;
    
    [self addSubview:scrollView];
    
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self);
        
        make.height.equalTo(@170);
        
        make.bottom.equalTo(self).offset(-30).priorityHigh();
        
    }];
    
    scrollView.delegate = self;
    
    scrollView.contentSize = CGSizeMake(5  * kScreen.size.width, 0);
    
    scrollView.pagingEnabled = YES;
    
    CGFloat imageW = [UIScreen mainScreen].bounds.size.width;
    
    UIImageView *tempImage;
    
    //添加图片
    for (int i = 0; i < 5; i++) {
        
        UIImageView *picture = [[UIImageView alloc]init];
        
        picture.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
        
        [scrollView addSubview:picture];
        
        [picture mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.height.equalTo(scrollView);
            
            make.width.equalTo(@(imageW));
            
            make.top.equalTo(scrollView);
            
            make.left.equalTo(tempImage? tempImage.mas_right : scrollView);
            
        }];
        
        tempImage = picture;
        
    }
}

#pragma mark --
#pragma mark --添加搜索框
-(void)addSearchBtn{

    UIButton *searchBtn = [[UIButton alloc]init];
    
    [searchBtn setImage:[UIImage imageNamed:@"homePage_topPoster_search"] forState:UIControlStateNormal];
    
    [searchBtn setTitle:@"影片/影院/影人 任你搜" forState:UIControlStateNormal];
    
    searchBtn.imageEdgeInsets = UIEdgeInsetsMake(2, 0, 2, kScreen.size.width - 100);
    
    searchBtn.titleEdgeInsets = UIEdgeInsetsMake(8, -80, 8, 0);
    
    searchBtn.adjustsImageWhenHighlighted = NO;
    
    [searchBtn setBackgroundImage:[UIImage imageNamed:@"v10_bt_gray"] forState:UIControlStateNormal];
    
    [searchBtn setTitleColor:[UIColor colorWithWhite:0.702 alpha:1.000] forState:UIControlStateNormal];
    
    [self addSubview:searchBtn];
    
    [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(@35);
        
        make.left.equalTo(self).offset(20);
        
        make.right.equalTo(self).offset(-15);
        
        make.bottom.equalTo(self).offset(-10);
        
    }];
    
    UIButton *scanBtn = [[UIButton alloc]init];
    
    [scanBtn setBackgroundImage:[UIImage imageNamed:@"icon_scan_barcode"] forState:UIControlStateNormal];
    
    [searchBtn addSubview:scanBtn];
    
    [scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.width.equalTo(@20);
        
        make.centerY.equalTo(searchBtn);
        
        make.right.equalTo(searchBtn).offset(-20);
        
    }];
    
    UIView *lineView = [[UIView alloc]init];
    
    lineView.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
    
    [searchBtn addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(@0.5);
        
        make.top.height.equalTo(scanBtn);
        
        make.right.equalTo(scanBtn.mas_left).offset(-20);
        
    }];
    
}

#pragma mark --
#pragma mark --添加pageControl
-(void)addPageControl{

    
}

-(void)addCoverView{
    
    UIView *coverView = [[UIView alloc]init];
    
    [self addSubview:coverView];
    
    coverView.backgroundColor = [UIColor whiteColor];
    
    [coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(@5);
        
        make.left.right.equalTo(self);
        
        make.top.equalTo(self.mas_bottom);
        
    }];
}








@end









































































